home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / XAMPP 1.4.14 / xampp-win32-1.4.14-installer.exe / xampp / php / pear / XML / SVG.php < prev    next >
PHP Script  |  2004-03-24  |  22KB  |  962 lines

  1. <?php
  2. /**
  3.  * XML_SVG
  4.  *
  5.  * Wrapper class that provides some examples and a few convenience
  6.  * methods.
  7.  *
  8.  * $Horde: framework/XML_SVG/SVG.php,v 1.15 2003/11/05 15:15:08 chuck Exp $
  9.  *
  10.  * Copyright 2002-2003 Chuck Hagenbuch <chuck@horde.org>
  11.  *
  12.  * See the enclosed file COPYING for license information (LGPL). If you
  13.  * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
  14.  *
  15.  * @package XML_SVG
  16.  */
  17. class XML_SVG {
  18.  
  19.     function example()
  20.     {
  21.         // Create an instance of XML_SVG_Document. All other objects
  22.         // will be added to this instance for printing. Set the height
  23.         // and width of the viewport.
  24.         $svg = &new XML_SVG_Document(array('width' => 400,
  25.                                            'height' => 200));
  26.  
  27.         // Create an instance of XML_SVG_Group. Set the style,
  28.         // transforms for child objects.
  29.         $g = &new XML_SVG_Group(array('style' => 'stroke:black',
  30.                                       'transform' => 'translate(200 100)'));
  31.  
  32.         // Add a parent to the g instance.
  33.         $g->addParent($svg);
  34.  
  35.         // The same results can be accomplished by making g a child of the svg.
  36.         // $svg->addChild($g);
  37.  
  38.         // Create and animate a circle.
  39.         $circle = &new XML_SVG_Circle(array('cx' => 0,
  40.                                            'cy' => 0,
  41.                                            'r' => 100,
  42.                                            'style' => 'stroke-width:3'));
  43.         $circle->addChild(new XML_SVG_Animate(array('attributeName' => 'r',
  44.                                                     'attributeType' => 'XML',
  45.                                                     'from' => 0,
  46.                                                     'to' => 75,
  47.                                                     'dur' => '3s',
  48.                                                     'fill' => 'freeze')));
  49.         $circle->addChild(new XML_SVG_Animate(array('attributeName' => 'fill',
  50.                                                     'attributeType' => 'CSS',
  51.                                                     'from' => 'green',
  52.                                                     'to' => 'red',
  53.                                                     'dur' => '3s',
  54.                                                     'fill' => 'freeze')));
  55.  
  56.         // Make the circle a child of g.
  57.         $g->addChild($circle);
  58.  
  59.         // Create and animate some text.
  60.         $text = &new XML_SVG_Text(array('text' => 'SVG chart!',
  61.                                        'x' => 0,
  62.                                        'y' => 0,
  63.                                        'style' => 'font-size:20;text-anchor:middle;'));
  64.         $text->addChild(new XML_SVG_Animate(array('attributeName' => 'font-size',
  65.                                                   'attributeType' => 'auto',
  66.                                                   'from' => 0,
  67.                                                   'to' => 20,
  68.                                                   'dur' => '3s',
  69.                                                   'fill' => 'freeze')));
  70.  
  71.         // Make the text a child of g.
  72.         $g->addChild($text);
  73.  
  74.         // Send a message to the svg instance to start printing.
  75.         $svg->printElement();
  76.     }
  77.  
  78. }
  79.  
  80. /**
  81.  * XML_SVG_Element
  82.  *
  83.  * This is the base class for the different SVG Element
  84.  * Objects. Extend this class to create a new SVG Element.
  85.  *
  86.  * @package XML_SVG
  87.  */
  88. class XML_SVG_Element {
  89.  
  90.     var $_elements = null;
  91.     var $_style = null;
  92.     var $_transform = null;
  93.     var $_id = null;
  94.  
  95.     // The constructor.
  96.     function XML_SVG_Element($params = array())
  97.     {
  98.         foreach ($params as $p => $v) {
  99.             $param = '_' . $p;
  100.             $this->$param = $v;
  101.         }
  102.     }
  103.  
  104.     // Most SVG elements can contain child elements. This method calls the
  105.     // printElement method of any child element added to this object by use
  106.     // of the addChild method.
  107.     function printElement()
  108.     {
  109.         // Loop and call
  110.         if (is_array($this->_elements)) {
  111.             foreach ($this->_elements as $child) {
  112.                 $child->printElement();
  113.             }
  114.         }
  115.     }
  116.  
  117.     // This method adds an object reference (or value, if $copy is
  118.     // true) to the _elements array.
  119.     function addChild(&$element, $copy = false)
  120.     {
  121.         if ($copy) {
  122.             $this->_elements[] = $element;
  123.         } else {
  124.             $this->_elements[] = &$element;
  125.         }
  126.     }
  127.  
  128.     // This method sends a message to the passed element requesting to be
  129.     // added as a child.
  130.     function addParent(&$parent)
  131.     {
  132.         if (is_subclass_of($parent, 'XML_SVG_Element')) {
  133.             $parent->addChild($this);
  134.         }
  135.     }
  136.  
  137.     function copy()
  138.     {
  139.         return $this;
  140.     }
  141.  
  142.     // Print each of the passed parameters, if they are set.
  143.     function printParams()
  144.     {
  145.         foreach (func_get_args() as $param) {
  146.             $_param = '_' . $param;
  147.             if (isset($this->$_param)) {
  148.                 switch ($param) {
  149.                 case 'filter':
  150.                     echo ' filter="url(#' . $this->$_param . ')"';
  151.                     break;
  152.  
  153.                 default:
  154.                     echo ' ' . str_replace('_', '-', $param) . '="' . $this->$_param . '"';
  155.                     break;
  156.                 }
  157.             }
  158.         }
  159.     }
  160.  
  161.     // Set any named attribute of an element to a value.
  162.     function setParam($param, $value)
  163.     {
  164.         $attr = '_' . $param;
  165.         $this->$attr = $value;
  166.     }
  167.  
  168.     // Get any named attribute of an element.
  169.     function getParam($param)
  170.     {
  171.         $attr = '_' . $param;
  172.         if (isset($this->$attr)) {
  173.             return $this->$attr;
  174.         } else {
  175.             return null;
  176.         }
  177.     }
  178.  
  179.     // Print out the object for debugging.
  180.     function debug()
  181.     {
  182.         echo '<pre>'; var_dump($this); echo '</pre>';
  183.     }
  184.  
  185. }
  186.  
  187. /** 
  188.  * XML_SVG_Fragment
  189.  *
  190.  * @package XML_SVG
  191.  */
  192. class XML_SVG_Fragment extends XML_SVG_Element {
  193.  
  194.     var $_width;
  195.     var $_height;
  196.     var $_viewBox;
  197.     var $_x;
  198.     var $_y;
  199.  
  200.     function printElement()
  201.     {
  202.         echo '<svg';
  203.         $this->printParams('id', 'width', 'height', 'x', 'y', 'viewBox', 'style');
  204.         echo ' xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">' . "\n";
  205.         parent::printElement();
  206.         echo "</svg>\n";
  207.     }
  208.  
  209.     function bufferObject()
  210.     {
  211.         ob_start();
  212.         $this->printElement();
  213.         $output = ob_get_contents();
  214.         ob_end_clean();
  215.  
  216.         return $output;
  217.     }
  218. }
  219.  
  220. /**
  221.  * XML_SVG_Document
  222.  *
  223.  * This extends the XML_SVG_Fragment class. It wraps the XML_SVG_Frament output
  224.  * with a content header, xml definition and doctype.
  225.  *
  226.  * @package XML_SVG
  227.  */
  228. class XML_SVG_Document extends XML_SVG_Fragment {
  229.  
  230.     function printElement()
  231.     {
  232.         header('Content-Type: image/svg+xml');
  233.  
  234.         print('<?xml version="1.0" encoding="iso-8859-1"?>'."\n");
  235.         print('<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
  236.             "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">' . "\n");
  237.  
  238.         parent::printElement();
  239.     }
  240.  
  241. }
  242.  
  243. /** 
  244.  * XML_SVG_Group
  245.  *
  246.  * @package XML_SVG
  247.  */
  248. class XML_SVG_Group extends XML_SVG_Element {
  249.  
  250.     function printElement()
  251.     {
  252.         echo '<g';
  253.         $this->printParams('id', 'style', 'transform', 'filter');
  254.         print(">\n");
  255.         parent::printElement();
  256.         print("</g>\n");
  257.     }
  258.  
  259. }
  260.  
  261. /** 
  262.  * XML_SVG_Textpath
  263.  *
  264.  * @package XML_SVG
  265.  */
  266. class XML_SVG_Textpath extends XML_SVG_Element {
  267.  
  268.     var $_text;
  269.     var $_x;
  270.     var $_y;
  271.     var $_dx;
  272.     var $_dy;
  273.     var $_rotate;
  274.     var $_textLength;
  275.     var $_lengthAdjust;
  276.  
  277.     function printElement($element = 'textpath')
  278.     {
  279.         echo '<' . $element;
  280.         $this->printParams('id', 'x', 'y', 'dx', 'dy', 'rotate',
  281.                            'textLength', 'lengthAdjust', 'style', 'transform');
  282.         echo '>' . htmlentities($this->_text);
  283.         parent::printElement();
  284.         echo "</$element>\n";
  285.     }
  286.  
  287.     function setShape($x, $y, $text)
  288.     {
  289.         $this->_x = $x;
  290.         $this->_y = $y;
  291.         $this->_text = $text;
  292.     }
  293.  
  294. }
  295.  
  296. /** 
  297.  * XML_SVG_Text
  298.  *
  299.  * @package XML_SVG
  300.  */
  301. class XML_SVG_Text extends XML_SVG_Textpath {
  302.  
  303.     function printElement()
  304.     {
  305.         parent::printElement('text');
  306.     }
  307.  
  308.     function setShape($x, $y, $text)
  309.     {
  310.         $this->_x = $x;
  311.         $this->_y = $y;
  312.         $this->_text = $text;
  313.     }
  314.  
  315. }
  316.  
  317. /** 
  318.  * XML_SVG_Tspan
  319.  *
  320.  * @package XML_SVG
  321.  */
  322. class XML_SVG_Tspan extends XML_SVG_Element {
  323.  
  324.     var $_text;
  325.     var $_x;
  326.     var $_y;
  327.     var $_dx;
  328.     var $_dy;
  329.     var $_rotate;
  330.     var $_textLength;
  331.     var $_lengthAdjust;
  332.  
  333.     function printElement()
  334.     {
  335.         echo '<tspan';
  336.         $this->printParams('id', 'x', 'y', 'dx', 'dy', 'rotate',
  337.                            'textLength', 'lengthAdjust', 'style', 'transform');
  338.         echo '>' . $this->_text;
  339.         if (is_array($this->_elements)) {
  340.             parent::printElement();
  341.         }
  342.         echo "</tspan>\n";
  343.     }
  344.  
  345.     function setShape($x, $y, $text)
  346.     {
  347.         $this->_x = $x;
  348.         $this->_y = $y;
  349.         $this->_text  = $text;
  350.     }
  351.  
  352. }
  353.  
  354. /** 
  355.  * XML_SVG_Circle
  356.  *
  357.  * @package XML_SVG
  358.  */
  359. class XML_SVG_Circle extends XML_SVG_Element {
  360.  
  361.     var $_cx;
  362.     var $_cy;
  363.     var $_r;
  364.  
  365.     function printElement()
  366.     {
  367.         echo '<circle';
  368.  
  369.         $this->printParams('id', 'cx', 'cy', 'r', 'style', 'transform');
  370.         if (is_array($this->_elements)) {
  371.             // Print children, start and end tag.
  372.             echo ">\n";
  373.             parent::printElement();
  374.             echo "</circle>\n";
  375.         } else {
  376.             // Print short tag.
  377.             echo "/>\n";
  378.         }
  379.     }
  380.  
  381.     function setShape($cx, $cy, $r)
  382.     {
  383.         $this->_cx = $cx;
  384.         $this->_cy = $cy;
  385.         $this->_r  = $r;
  386.     }
  387.  
  388. }
  389.  
  390. /** 
  391.  * XML_SVG_Line
  392.  *
  393.  * @package XML_SVG
  394.  */
  395. class XML_SVG_Line extends XML_SVG_Element {
  396.  
  397.     var $_x1;
  398.     var $_y1;
  399.     var $_x2;
  400.     var $_y2;
  401.  
  402.     function printElement()
  403.     {
  404.         echo '<line';
  405.         $this->printParams('id', 'x1', 'y1', 'x2', 'y2', 'style');
  406.         if (is_array($this->_elements)) {
  407.             // Print children, start and end tag.
  408.             print(">\n");
  409.             parent::printElement();
  410.             print("</line>\n");
  411.         } else {
  412.             // Print short tag.
  413.             print("/>\n");
  414.         }
  415.     }
  416.  
  417.     function setShape($x1, $y1, $x2, $y2)
  418.     {
  419.         $this->_x1 = $x1;
  420.         $this->_y1 = $y1;
  421.         $this->_x2  = $x2;
  422.         $this->_y2  = $y2;
  423.     }
  424.  
  425. }
  426.  
  427. /** 
  428.  * XML_SVG_Rect
  429.  *
  430.  * @package XML_SVG
  431.  */
  432. class XML_SVG_Rect extends XML_SVG_Element {
  433.  
  434.     var $_x;
  435.     var $_y;
  436.     var $_width;
  437.     var $_height;
  438.     var $_rx;
  439.     var $_ry;
  440.  
  441.     function printElement()
  442.     {
  443.         echo '<rect';
  444.         $this->printParams('id', 'x', 'y', 'width', 'height',
  445.                            'rx', 'ry', 'style');
  446.         if (is_array($this->_elements)) {
  447.             // Print children, start and end tag.
  448.             print(">\n");
  449.             parent::printElement();
  450.             print("</rect>\n");
  451.         } else {
  452.             // Print short tag.
  453.             print("/>\n");
  454.         }
  455.     }
  456.  
  457.     function setShape($x, $y, $width, $height)
  458.     {
  459.         $this->_x = $x;
  460.         $this->_y = $y;
  461.         $this->_width  = $width;
  462.         $this->_height  = $height;
  463.     }
  464.  
  465. }
  466.  
  467. /** 
  468.  * XML_SVG_Ellipse
  469.  *
  470.  * @package XML_SVG
  471.  */
  472. class XML_SVG_Ellipse extends XML_SVG_Element {
  473.  
  474.     var $_cx;
  475.     var $_cy;
  476.     var $_rx;
  477.     var $_ry;
  478.  
  479.     function printElement()
  480.     {
  481.         echo '<ellipse';
  482.         $this->printParams('id', 'cx', 'cy', 'rx', 'ry', 'style', 'transform');
  483.         if (is_array($this->_elements)) {
  484.             // Print children, start and end tag.
  485.             print(">\n");
  486.             parent::printElement();
  487.             print("</ellipse>\n");
  488.         } else {
  489.             // Print short tag.
  490.             print(" />\n");
  491.         }
  492.     }
  493.  
  494.     function setShape($cx, $cy, $rx, $ry)
  495.     {
  496.         $this->_cx = $cx;
  497.         $this->_cy = $cy;
  498.         $this->_rx  = $rx;
  499.         $this->_ry  = $ry;
  500.     }
  501.  
  502. }
  503.  
  504. /** 
  505.  * XML_SVG_Polyline
  506.  *
  507.  * @package XML_SVG
  508.  */
  509. class XML_SVG_Polyline extends XML_SVG_Element {
  510.  
  511.     var $_points;
  512.  
  513.     function printElement()
  514.     {
  515.         echo '<polyline';
  516.         $this->printParams('id', 'points', 'style', 'transform');
  517.  
  518.         if (is_array($this->_elements)) {
  519.             // Print children, start and end tag.
  520.             print(">\n");
  521.             parent::printElement();
  522.             print("</polyline>\n");
  523.         } else {
  524.             // Print short tag.
  525.             print("/>\n");
  526.         }
  527.     }
  528.  
  529.     function setShape($points)
  530.     {
  531.         $this->_points = $points;
  532.     }
  533.  
  534. }
  535.  
  536. /** 
  537.  * XML_SVG_Polygon
  538.  *
  539.  * @package XML_SVG
  540.  */
  541. class XML_SVG_Polygon extends XML_SVG_Element {
  542.  
  543.     var $_points;
  544.  
  545.     function printElement()
  546.     {
  547.         echo '<polygon';
  548.         $this->printParams('id', 'points', 'style', 'transform');
  549.         if (is_array($this->_elements)) {
  550.             // Print children, start and end tag.
  551.             print(">\n");
  552.             parent::printElement();
  553.             print("</polygon>\n");
  554.         } else {
  555.             // Print short tag.
  556.             print("/>\n");
  557.         }
  558.     }
  559.  
  560.     function setShape($points)
  561.     {
  562.         $this->_points = $points;
  563.     }
  564.  
  565. }
  566.  
  567. /** 
  568.  * XML_SVG_Path
  569.  *
  570.  * @package XML_SVG
  571.  */
  572. class XML_SVG_Path extends XML_SVG_Element {
  573.  
  574.     var $_d;
  575.  
  576.     function printElement()
  577.     {
  578.         echo '<path';
  579.         $this->printParams('id', 'd', 'style', 'transform');
  580.         if (is_array($this->_elements)) {
  581.             // Print children, start and end tag.
  582.             print(">\n");
  583.             parent::printElement();
  584.             print("</path>\n");
  585.         } else {
  586.             // Print short tag.
  587.             print("/>\n");
  588.         }
  589.     }
  590.  
  591.     function setShape($d)
  592.     {
  593.         $this->_d = $d;
  594.     }
  595.  
  596. }
  597.  
  598. /** 
  599.  * XML_SVG_Image
  600.  *
  601.  * @package XML_SVG
  602.  */
  603. class XML_SVG_Image extends XML_SVG_Element {
  604.  
  605.     var $_x;
  606.     var $_y;
  607.     var $_width;
  608.     var $_height;
  609.     var $_href;
  610.  
  611.     function printElement()
  612.     {
  613.         echo '<image';
  614.         $this->printParams('id', 'x', 'y', 'width', 'height', 'style');
  615.         if (!empty($this->_href)) {
  616.             echo ' xlink:href="' . $this->_href . '"';
  617.         }
  618.         if (is_array($this->_elements)) {
  619.             // Print children, start and end tag.
  620.             echo ">\n";
  621.             parent::printElement();
  622.             echo "</image>\n";
  623.         } else {
  624.             // Print short tag.
  625.             echo " />\n";
  626.         }
  627.     }
  628.  
  629.     function setShape($x, $y, $width, $height)
  630.     {
  631.         $this->_x = $x;
  632.         $this->_y = $y;
  633.         $this->_width  = $width;
  634.         $this->_height  = $height;
  635.     }
  636.  
  637. }
  638.  
  639. /** 
  640.  * XML_SVG_Animate
  641.  *
  642.  * @package XML_SVG
  643.  */
  644. class XML_SVG_Animate extends XML_SVG_Element {
  645.  
  646.     var $_attributeName;
  647.     var $_attributeType;
  648.     var $_from;
  649.     var $_to;
  650.     var $_begin;
  651.     var $_dur;
  652.     var $_fill;
  653.  
  654.     function printElement()
  655.     {
  656.         echo '<animate';
  657.         $this->printParams('id', 'attributeName', 'attributeType', 'from', 'to',
  658.                            'begin', 'dur', 'fill');
  659.         if (is_array($this->_elements)) {
  660.             // Print children, start and end tag.
  661.             echo ">\n";
  662.             parent::printElement();
  663.             echo "</animate>\n";
  664.         } else {
  665.             echo " />\n";
  666.         }
  667.     }
  668.  
  669.     function setShape($attributeName, $attributeType = '', $from = '',
  670.                       $to = '', $begin = '', $dur = '', $fill = '')
  671.     {
  672.         $this->_attributeName = $attributeName;
  673.         $this->_attributeType = $attributeType;
  674.         $this->_from  = $from;
  675.         $this->_to = $to;
  676.         $this->_begin = $begin;
  677.         $this->_dur = $dur;
  678.         $this->_fill = $fill;
  679.     }
  680.  
  681. }
  682.  
  683. /** 
  684.  * XML_SVG_Filter
  685.  *
  686.  * @package XML_SVG
  687.  */
  688. class XML_SVG_Filter extends XML_SVG_Element {
  689.  
  690.     function printElement()
  691.     {
  692.         echo '<filter';
  693.         $this->printParams('id');
  694.         if (is_array($this->_elements)) {
  695.             // Print children, start and end tag.
  696.             echo ">\n";
  697.             parent::printElement();
  698.             echo "</filter>\n";
  699.         } else {
  700.             echo " />\n";
  701.         }
  702.     }
  703.  
  704.     function addPrimitive($primitive, $params)
  705.     {
  706.         $this->addChild(new XML_SVG_FilterPrimitive($primitive, $params));
  707.     }
  708.  
  709. }
  710.  
  711. /** 
  712.  * XML_SVG_FilterPrimitive
  713.  *
  714.  * @package XML_SVG
  715.  */
  716. class XML_SVG_FilterPrimitive extends XML_SVG_Element {
  717.  
  718.     var $_primitives = array('Blend',
  719.                              'ColorMatrix',
  720.                              'ComponentTransfer',
  721.                              'Composite',
  722.                              'ConvolveMatrix',
  723.                              'DiffuseLighting',
  724.                              'DisplacementMap',
  725.                              'Flood',
  726.                              'GaussianBlur',
  727.                              'Image',
  728.                              'Merge',
  729.                              'Morphology',
  730.                              'Offset',
  731.                              'SpecularLighting',
  732.                              'Tile',
  733.                              'Turbulence');
  734.  
  735.     var $_primitive;
  736.  
  737.     var $_in;
  738.     var $_in2;
  739.     var $_result;
  740.     var $_x;
  741.     var $_y;
  742.     var $_dx;
  743.     var $_dy;
  744.     var $_width;
  745.     var $_height;
  746.     var $_mode;
  747.     var $_type;
  748.     var $_values;
  749.     var $_operator;
  750.     var $_k1;
  751.     var $_k2;
  752.     var $_k3;
  753.     var $_k4;
  754.     var $_surfaceScale;
  755.     var $_diffuseConstant;
  756.     var $_kernelUnitLength;
  757.     var $_floor_color;
  758.     var $_flood_opacity;
  759.  
  760.     function XML_SVG_FilterPrimitive($primitive, $params = array())
  761.     {
  762.         parent::XML_SVG_Element($params);
  763.         $this->_primitive = $primitive;
  764.     }
  765.  
  766.     function printElement()
  767.     {
  768.         $name = 'fe' . $this->_primitive;
  769.         echo '<' . $name;
  770.         $this->printParams('id', 'x', 'y', 'dx', 'dy', 'width', 'height', 'in', 'in2',
  771.                            'result', 'mode', 'type', 'values', 'operator',
  772.                            'k1', 'k2', 'k3', 'k4', 'surfaceScale', 'stdDeviation',
  773.                            'diffuseConstant', 'kernelUnitLength',
  774.                            'flood_color', 'flood_opacity');
  775.         if (is_array($this->_elements)) {
  776.             // Print children, start and end tag.
  777.             echo ">\n";
  778.             parent::printElement();
  779.             echo '</' . $name . '>';
  780.         } else {
  781.             echo '/>';
  782.         }
  783.     }
  784.  
  785.     /**
  786.      * For feMerge elements.
  787.      */
  788.     function addMergeNode($in)
  789.     {
  790.         $this->addChild(new XML_SVG_FilterMergeNode(array('in' => $in)));
  791.     }
  792.  
  793. }
  794.  
  795. /** 
  796.  * XML_SVG_FilterMergeNode
  797.  *
  798.  * @package XML_SVG
  799.  */
  800. class XML_SVG_FilterMergeNode extends XML_SVG_Element {
  801.  
  802.     var $_in;
  803.  
  804.     function printElement()
  805.     {
  806.         echo '<feMergeNode';
  807.         $this->printParams('in');
  808.         echo '/>';
  809.     }
  810.  
  811. }
  812.  
  813. /** 
  814.  * XML_SVG_Use
  815.  *
  816.  * @package XML_SVG
  817.  */
  818. class XML_SVG_Use extends XML_SVG_Element {
  819.  
  820.     var $_symbol;
  821.  
  822.     function XML_SVG_Use($symbol, $params = array())
  823.     {
  824.         parent::XML_SVG_Element($params);
  825.         $this->_symbol = $symbol;
  826.     }
  827.  
  828.     function printElement()
  829.     {
  830.         echo '<use xlink:href="#' . $this->_symbol . '"/>';
  831.     }
  832.  
  833. }
  834.  
  835. /** 
  836.  * XML_SVG_Defs
  837.  *
  838.  * @package XML_SVG
  839.  */
  840. class XML_SVG_Defs extends XML_SVG_Element {
  841.  
  842.     function printElement()
  843.     {
  844.         echo '<defs';
  845.         $this->printParams('id', 'style', 'transform');
  846.         echo ">\n";
  847.         parent::printElement();
  848.         echo "</defs>\n";
  849.     }
  850.  
  851. }
  852.  
  853. /** 
  854.  * XML_SVG_Marker
  855.  *
  856.  * @package XML_SVG
  857.  */
  858. class XML_SVG_Marker extends XML_SVG_Element {
  859.  
  860.     var $_refX;
  861.     var $_refY;
  862.     var $_markerUnits;
  863.     var $_markerWidth;
  864.     var $_markerHeight;
  865.     var $_orient;
  866.  
  867.     function printElement()
  868.     {
  869.         echo '<marker';
  870.         $this->printParams('id', 'refX', 'refY', 'markerUnits',
  871.                            'markerWidth', 'markerHeight', 'orient');
  872.         if (is_array($this->_elements)) { // Print children, start and end tag.
  873.             print(">\n");
  874.             parent::printElement();
  875.             print("</marker>\n");
  876.         } else {
  877.             print("/>\n");
  878.         }
  879.     }
  880.  
  881.     function setShape($refX = '', $refY = '', $markerUnits = '',
  882.                       $markerWidth = '', $markerHeight = '', $orient = '')
  883.     {
  884.         $this->_refX = $refX;
  885.         $this->_refY  = $refY;
  886.         $this->_markerUnits = $markerUnits;
  887.         $this->_markerWidth = $markerWidth;
  888.         $this->_markerHeight = $markerHeight;
  889.         $this->_orient = $orient;
  890.     }
  891.  
  892. }
  893.  
  894. /** 
  895.  * XML_SVG_Title 
  896.  *
  897.  * @package XML_SVG
  898. */
  899. class XML_SVG_Title extends XML_SVG_Element {
  900.  
  901.     var $_title;
  902.  
  903.     function printElement()
  904.     {
  905.         echo '<title';
  906.         $this->printParams('id', 'style');
  907.         print(">\n");
  908.         print($this->_title);
  909.         parent::printElement();
  910.         print("</title>\n");
  911.     }
  912.  
  913. }
  914.  
  915. /** 
  916.  * XML_SVG_Desc
  917.  *
  918.  * @package XML_SVG
  919.  */
  920. class XML_SVG_Desc extends XML_SVG_Element {
  921.  
  922.     var $_desc;
  923.  
  924.     function printElement()
  925.     {
  926.         echo '<desc';
  927.         $this->printParams('id', 'style');
  928.         echo '>' . $this->_desc;
  929.         parent::printElement();
  930.         echo "</desc>\n";
  931.     }
  932.  
  933. }
  934.  
  935. /** 
  936.  * XML_SVG_Tref
  937.  *
  938.  * @package XML_SVG
  939.  */
  940. class XML_SVG_Tref extends XML_SVG_Element {
  941.  
  942.     var $_text;
  943.     var $_x;
  944.     var $_y;
  945.     var $_dx;
  946.     var $_dy;
  947.     var $_rotate;
  948.     var $_textLength;
  949.     var $_lengthAdjust;
  950.  
  951.     function printElement()
  952.     {
  953.         echo '<tref';
  954.         $this->printParams('id', 'x', 'y', 'dx', 'dy', 'rotate',
  955.                            'textLength', 'lengthAdjust', 'style');
  956.         echo '>' . $this->_text;
  957.         parent::printElement();
  958.         echo "</tref>\n";
  959.     }
  960.  
  961. }
  962.